<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<style>
    #imgs{
        width: 100px;
        height: 100px;
        background-color: blueviolet;
        position: absolute;
      
    }
</style>
<body>
 <div id="imgs"></div>
    <script>
      function setimg(delay=1000,callback){
           return  new Promise(resolve=>{
              let id= setInterval(()=>{
                      callback(id,resolve)
                 },delay);
           });
      }
      setimg(10,(id,resolve)=>{
           let img=document.querySelector("#imgs");
           let left=parseInt(window.getComputedStyle(img).left);
         img.style.left=left+10 +"px";
         if(left>1000){
             console.log(left);
             
             clearInterval(id);
             //想要再使用就再resolve
             resolve(img);
         }
      }).then(img=>{
          setimg(10,(id,resolve)=>{
              let width=parseInt(window.getComputedStyle(value).width);
              img.style.width=width-10+"px";
              if(width<20){
            clearInterval(id);
              }
          })
      })
    </script>
</body>
</html>